package com.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.SessionFactoryUtils;

import com.bean.Privilegio;
import com.dao.RecursosDao;

public class PrivilegioDaoImpl implements RecursosDao {
	Logger log	= Logger.getLogger(PrivilegioDaoImpl.class);
	
	private SessionFactory	sessionFactory;
	
	@Override
	public Object buscaRegistroPorId(Object registro) {
		log.debug("begin");
		Privilegio privilegio	= new Privilegio();
		privilegio	= (Privilegio) registro;
		Session session		= SessionFactoryUtils.getSession(sessionFactory, true);
		Criteria criterio	= session.createCriteria(Privilegio.class);
		criterio.add(Restrictions.eq("ID_PRIVILEGIO", privilegio.getIdPrivilegio()));
		log.debug("finally");
		return criterio.uniqueResult();
	}

	@SuppressWarnings("unchecked")
	@Override
	public <T> List<T> listaDeRegistros() {
		log.debug("begin");
		Session session		= SessionFactoryUtils.getSession(sessionFactory, true);
		Criteria criterio	= session.createCriteria(Privilegio.class);
		log.debug("finally");
		return criterio.list();
	}


}
